﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcShop.Models.ViewDataModels;

namespace MvcShop.Models.Repositories
{
    public class AdsRepository:BaseRepositoryBase<Ads>,IAdsRepository<Ads>
    {
        public AdsRepository()
        {
            this.EntitiesSetName = "Adses";
        }

        public IEnumerable<AdList> GetAdList()
        {
            var query = (from ads in this.EntitySet
                         select new AdList
                         {
                             AdsId = ads.AdsId,
                             Mark = ads.Mark,
                             IsUsed = ads.IsUsed,
                             AddDate = ads.AddDate,
                             EndDate = ads.EndDate
                         }).ToList();
            return query;
        }
    }

    public class AdPositionRepository : BaseRepositoryBase<AdPosition>, IAdPositionRepository<AdPosition>
    {
        public AdPositionRepository()
        {
            this.EntitiesSetName = "AdPositions";
        }

        public bool CheckAdMark(string mark)
        {
            var query = this.EntitySet.Count(c => c.Mark == mark);
            return query != 0 ? true : false;
        }
    }
}
